/*
 * checkout.java
 *
 * Created on March 26, 2007, 7:11 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.actions;

import edu.byu.isys413.group1E.data.BackupDataBO;
import edu.byu.isys413.group1E.data.BackupDataDAO;
import edu.byu.isys413.group1E.data.CustomerBO;
import edu.byu.isys413.group1E.data.MembershipBO;
import edu.byu.isys413.group1E.handlers.FileHandler;
import java.util.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.FileItem;
import javax.servlet.http.*;
import edu.byu.isys413.group1E.data.*;
import edu.byu.isys413.group1E.handlers.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**This action uploads a photo to the database, and adds the photo to the transaction
 *
 * @author Kendall Frazier
 */
public class uploadphoto implements edu.byu.isys413.web.Action {
    
    /**
     * Creates a new instance of checkout
     */
    public uploadphoto() {
    }
    
    /**
     *Processes this method uploads a photo to the database, and also adds the charge for that upload to the transaction
     *
     *@param HttpServletRequest
     *@param HttpServletResponse
     *
     *@return String the name of the jsp to call
     */
    public String process(HttpServletRequest request, HttpServletResponse response) throws Exception {

        
        HttpSession session = request.getSession();
        CustomerBO cust = (CustomerBO)session.getAttribute("customer");
        MembershipBO memb = cust.getCustMembership();
        ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
        List paramList = servletFileUpload.parseRequest(request);
        Map params = new TreeMap();
        for (int i = 0; i < paramList.size(); i++) {
            FileItem item = (FileItem)paramList.get(i);
            params.put(item.getFieldName(), item);
        }//for
        FileItem item1 = (FileItem)params.get("photo");
        String guid = FileHandler.getInstance().saveFileToDB(item1,memb.getMembershipID(), "print");
  
        
        request.setAttribute("photoid", guid);
        
        return "specprint.jsp";
        
    }//process
    
    
}//checkout class
